﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using FluentData;
using Huazhu.PMS.Framework.Data;

namespace Huazhu.PMS.Framework.Core
{
    internal class CredentialDataAccess:BaseDataAccess
    {
        internal List<Credential> GetUserCredentials()
        {
            var sql = "SELECT [iAuthID], [sContent], [dEndTime] FROM [User_Auth]  WHERE  [sUserName]=@NAME AND [dBeginTime]<=GETDATE() AND [dEndTime]>=GETDATE() ";

            using (var context = DataHelper.GetBaseDbContext())
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Credential));
                var credential =
                    context.Sql(sql).QueryMany<Credential>(delegate(Credential map, IDataReader reader)
                    {
                        map = serializer.Deserialize(new StringReader(reader.GetString("sContet"))) as Credential;
                        //TODO:更多字段
                    });
                return credential;
            }
        }
    }
}
